const Router = require('koa-router');
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
router.post('/app/getGoodByBar', async ctx => {
    let tenantId= ctx.user.tenantId
    let body= ctx.request.body
    let code= body.code

    let sql = `select id,name,spec,unit1,unit2 from v_goods where tenantId=${tenantId} and (barCode='${code}' or barCode1 ='${code}') `

    let list = await db.query(`select * from (${sql}) a order by id desc  `,{type: QueryTypes})
    if(list.length > 0) {
        return ctx.suc('', {
            total: 1,
            list
        })
    }
    else {
        return ctx.err('没有该条码对应商品')
    }
})



module.exports = router;